package tv.geir.slackspace.code;

import java.io.File;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Represents a classpath entry on file (jarfile or directory)
 * 
 * @author Geir Gullestad Pettersen
 *
 */
public class ClasspathEntry extends File{

	/**
	 * default serial uid
	 */
	private static final long serialVersionUID = 1L;

	public ClasspathEntry( String path ) {
		super(path);
	}

	public boolean isJarFile() {
		return super.isFile() && super.getName().endsWith( ".jar" );
	}
	
	public boolean isValidClasspathEntry() {
		return exists() && (isJarFile() || isDirectory());
	}
	
	public String toString() {
		return new ToStringBuilder(this)
		.append( "path",super.getAbsolutePath())
		.append( "jarfile", isJarFile() )
		.append( "directory", isDirectory() )
		.toString();
	} 
	
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return new HashCodeBuilder().append( super.getPath().toString() ).hashCode();
	}
}
